﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cspl.AnimalFight.Lib.Interface;
using Cspl.AnimalFight.Lib.EventHandlers;

namespace Cspl.AnimalFight.Lib.Data
{
    class Dog :AnimalBase,IAttack,IDefense,IAttackable
    {
        private DogMood _mood;
        public event DefendEventHandler DefentEvent;
        public event AttackDelegate AttackEvent;

        public bool IsDefending
        {
            get;
            set;
        }


        public DogMood Mood
        {
            get { return _mood; }
            set { _mood = value; }
        }
        

        public void Defend()
        {
            if (DefentEvent != null)
            {
                DefentEvent(this, new DefenseEventHandler
                {
                    AnimalName = this.AnimalName,
                    Target = Animals.Dog
                });
            }
        }
 
        public void Attack(Animals target)
        {
            int RealAttackPower = 0;
            if (this.Mood == DogMood.Bad)
            {
                RealAttackPower = (int)(0.5 * this.AttackPower);
            }
            else {
                RealAttackPower = this.AttackPower;
            }

            if (AttackEvent != null) {
                AttackEventHandler eventHandler = new AttackEventHandler{
                    AttackPower = RealAttackPower,
                    Target = target
                };
                AttackEvent(this, eventHandler);
            }   
        }

        public override void Escape()
        {
            Console.WriteLine("Dog has escaped.");
        }

        public void Attacked(int attackPower)
        {
            if (this._hasEscaped) {
                Console.WriteLine("{0} has escaped. Cannot be attacked",this.AnimalName);
            }
            else if (this._isDead)
            {
                Console.WriteLine("{0} is already dead. Cannot be attacked", this.AnimalName);
            }
            else {
                int healthlose = 0;
                int realDP = this.IsDefending ? this.DefensePower + 10 : this.DefensePower;

                if (this.Mood == DogMood.Bad) {
                    healthlose = this.HealthPower - (attackPower - realDP);
                }
            }
        }
    }

    public enum DogMood { Good, Bad }
}
